//
//  HNSH_PaySuccessViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/3/2.
//

#import "HNSH_PaySuccessViewController.h"

//vc
#import "HNSH_OrderListManager.h"

@interface HNSH_PaySuccessViewController ()

/** */
@property (nonatomic, strong)UIButton * doneBtn;
/** */
@property (nonatomic, strong)UIImageView * imgView;
/** */
@property (nonatomic, strong)UILabel * titleLabel;
/** */
@property (nonatomic, strong)UILabel * typeLabel;
/** */
@property (nonatomic, strong)UILabel * moneyLabel;
/* orderButton */
@property (nonatomic, strong) UIButton *orderButton;
/** */
@property (nonatomic, strong)UIButton * hdsyBtn;
/** */
@property (nonatomic, strong)UILabel * desLabel;

@end

@implementation HNSH_PaySuccessViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self showNavTitle:@"付款结果" showLeftItem:YES];
    self.navView.backgroundColor = [UIColor clearColor];
    
    __weak typeof(self) weakSelf = self;
    self.navView.leftBlock = ^{
        [weakSelf doneBtnAction];
    };
        
    [self.view addSubview:self.doneBtn];
    [self addAllViews];
    [self addAllLayout];
}

- (void)addAllViews{
    
    [self.view addSubview:self.imgView];
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.typeLabel];
    [self.view addSubview:self.moneyLabel];
    
    [self.view addSubview:self.orderButton];
    [self.view addSubview:self.hdsyBtn];
    [self.view addSubview:self.desLabel];
}

- (void)addAllLayout{
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(kNavBarAndStatusBarHeight+24);
        make.width.height.mas_equalTo(60);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(16);
        make.centerX.equalTo(self.imgView.mas_centerX);
        make.height.mas_equalTo(25);
    }];
    
    [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(12);
        make.centerX.equalTo(self.titleLabel.mas_centerX);
        make.height.mas_equalTo(20);
    }];
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.typeLabel.mas_bottom).offset(4);
        make.centerX.equalTo(self.typeLabel.mas_centerX);
        make.height.mas_equalTo(20);
    }];
    
    if (self.hiddenOrder) {
        self.orderButton.hidden = YES;
        [self.hdsyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.moneyLabel.mas_bottom).offset(32);
            make.right.mas_equalTo(-16);
            make.width.mas_equalTo(kScreenWidth-32);
            make.height.mas_equalTo(44);
        }];
        self.hdsyBtn.hidden = self.fromAuth;
    } else {
        CGFloat width = (kScreenWidth-48)/2;
        [self.orderButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.moneyLabel.mas_bottom).offset(32);
            make.left.mas_equalTo(16);
            make.width.mas_equalTo(width);
            make.height.mas_equalTo(44);
        }];
        [self.hdsyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.moneyLabel.mas_bottom).offset(32);
            make.right.mas_equalTo(-16);
            make.width.mas_equalTo(width);
            make.height.mas_equalTo(44);
        }];
        self.orderButton.hidden = self.hdsyBtn.hidden = self.fromAuth;
    }
    
    [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.hdsyBtn.mas_bottom).offset(40);
    }];
}

//MARK: Myself Methods
- (void)doneBtnAction{
    if (self.navigationController.viewControllers.count >= 4) {
        if (self.fromAuth) {
            [self.navigationController popToViewController:self.navigationController.viewControllers[self.navigationController.viewControllers.count-3] animated:YES];
            return;
        }
        [self.navigationController popToViewController:self.navigationController.viewControllers[self.navigationController.viewControllers.count-4] animated:YES];
    } else {
        [self.navigationController popToViewController:self.navigationController.viewControllers[self.navigationController.viewControllers.count-3] animated:YES];
    }
}

- (void)hdsyBtnAction{
    self.tabBarController.selectedIndex = 0;
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)orderButtonClick {
    if (self.fromWeb) {
        ST_BaseWebController * vc = [ST_BaseWebController new];
        vc.titleString = @"";
        NSLog(@"ssssssssssssssss ==> %@",[NSString stringWithFormat:@"%@%@&appToken=%@",k_user_home_Order,[ST_UserManager shareInstance].other_token,[ST_UserManager shareInstance].access_token]);
        [vc loadURLString:[NSString stringWithFormat:@"%@%@&appToken=%@",k_user_home_Order,[ST_UserManager shareInstance].other_token,[ST_UserManager shareInstance].access_token]];
        [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
    } else {
        HNSH_OrderListManager *vc = [[HNSH_OrderListManager alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

//MARK: Getter Methods
- (UIButton *)doneBtn{
    if (!_doneBtn) {
        _doneBtn = [UIButton new];
        _doneBtn.frame = CGRectMake(kScreenWidth - 70, kStatusBarHeight, 70, 44);
        [_doneBtn setTitle:@"完成" forState:UIControlStateNormal];
        [_doneBtn setTitleColor:[UIColor appBlack333LabelColor] forState:UIControlStateNormal];
        _doneBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _doneBtn;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.image = [UIImage imageNamed:@"goods_pay_sucsse_icon"];
    }
    return _imgView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont boldSystemFontOfSize:18];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#40C110"];
        _titleLabel.text = @"订单支付成功";
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}

- (UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = [UILabel new];
        _typeLabel.font = [UIFont boldSystemFontOfSize:14];
        _typeLabel.textColor = [UIColor appBlackLabelColor];
        _typeLabel.textAlignment = NSTextAlignmentCenter;
        _typeLabel.text = [NSString stringWithFormat:@"支付方式：%@", self.typeStr];
        _typeLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:_typeLabel.text SelectContent:@"支付方式：" CommonFont:_typeLabel.font SpeFont:[UIFont systemFontOfSize:14] Color:[UIColor appGrayLabelColor]];
    }
    return _typeLabel;
}

- (UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [UILabel new];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:14];
        _moneyLabel.textColor = [UIColor appBlackLabelColor];
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
        _moneyLabel.text = [NSString stringWithFormat:@"支付金额：%@", self.priceStr];
        _moneyLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:_moneyLabel.text SelectContent:@"支付金额：" CommonFont:_moneyLabel.font SpeFont:[UIFont systemFontOfSize:14] Color:[UIColor appGrayLabelColor]];
    }
    return _moneyLabel;
}

- (UIButton *)orderButton{
    if (!_orderButton) {
        _orderButton = [UIButton new];
        [_orderButton setTitle:@"查看订单" forState:UIControlStateNormal];
        [_orderButton setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _orderButton.titleLabel.font = [UIFont systemFontOfSize:16];
        _orderButton.backgroundColor = [UIColor colorWithHexString:@"#FFF5F3"];
        _orderButton.layer.cornerRadius = 20;
        _orderButton.layer.masksToBounds = YES;
        [_orderButton addTarget:self action:@selector(orderButtonClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _orderButton;
}

- (UIButton *)hdsyBtn{
    if (!_hdsyBtn) {
        _hdsyBtn = [UIButton new];
        [_hdsyBtn setTitle:@"回到首页" forState:UIControlStateNormal];
        [_hdsyBtn setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _hdsyBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        _hdsyBtn.backgroundColor = [UIColor appGreenColor];
        _hdsyBtn.layer.cornerRadius = 20;
        _hdsyBtn.layer.masksToBounds = YES;
        [_hdsyBtn addTarget:self action:@selector(hdsyBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _hdsyBtn;
}

- (UILabel *)desLabel{
    if (!_desLabel) {
        _desLabel = [UILabel new];
        _desLabel.font = [UIFont systemFontOfSize:14];
        _desLabel.textColor = [UIColor colorWithHexString:@"#999999"];
        _desLabel.numberOfLines = 0;
        _desLabel.text = @"温馨提示:\n万物悦享不会以订单异常、系统异常为由要求您点击任何网址链接进行退款操作。";
    }
    return _desLabel;
}

@end
